home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / rap101.zip / DEMO.RAP < prev    next >
Text File  |  1988-10-26  |  6KB  |  314 lines

  1. ; DEMO.RAP -- Interactive demo of some common.rap functions
  2. ;
  3. ;     Kirk Parker, 19-Nov-87
  4. ;
  5.  
  6. .define .TESTDECL declare $my_prompt,$my_def,#my_min,#my_max,#my_oblig,#first_time
  7.  
  8. .define .STRING 1
  9. .define .NUMERIC 2
  10. .define .FILE 3
  11.  
  12. .include common.rap
  13.  
  14. ; ----------------------------------------------------------
  15.  
  16. proc main
  17.  
  18. declare #i
  19.  
  20. $test[0]=YES
  21. $test[1]=NO
  22. $test[2]=GET_STR
  23. $test[3]=GET_NUM
  24. $test[4]=GET_CODE
  25. $test[5]=GET_FILESPEC
  26.  
  27. #end_test = 6
  28.  
  29. ch
  30. t:
  31. t:          Demonstration of RAP SUBROUTINE LIBRARY
  32. t:
  33. t:
  34. loop while (#i < #end_test)
  35.     if (*yes("Test subroutine $test[#i]","",""))
  36.         xi test_$test[#i]
  37.     endif
  38.     #i = #i + 1
  39. endloop
  40.  
  41. endproc
  42.  
  43. ; ----------------------------------------------------------
  44.  
  45. proc test_get_str()
  46.  
  47. .TESTDECL
  48. declare $my_str
  49.  
  50. #first_time = 1
  51.  
  52. loop
  53.     get_params(.STRING,#first_time,"get_str")
  54.  
  55.     #first_time = 0
  56.  
  57.     $my_str=*get_str($my_prompt,$my_def,"",#my_min,#my_max,#my_oblig)
  58.     t:$skip   You entered <$my_str>
  59. until (*no("Repeat this test","",""))
  60.  
  61. endproc
  62.  
  63. ; ----------------------------------------------------------
  64.  
  65. proc test_get_code()
  66.  
  67. .TESTDECL
  68. declare $my_code
  69.  
  70. #first_time = 1
  71.  
  72. loop
  73.     get_params(.STRING,#first_time,"get_code")
  74.  
  75.     #first_time = 0
  76.  
  77.     $my_code=*get_code($my_prompt,$my_def,"",#my_min,#my_max)
  78.     t:$skip   You entered <$my_code>
  79. until (*no("Repeat this test","",""))
  80.  
  81. endproc
  82.  
  83. ; ----------------------------------------------------------
  84.  
  85. proc showyes(#n)
  86.  
  87. t:$skip   Your answer was \
  88. if (#n == 0)
  89.     t:NO.   \
  90. else
  91.     t:YES.  \
  92. endif
  93.  
  94. t:(function returned \
  95. endproc
  96.  
  97. ; ----------------------------------------------------------
  98.  
  99. proc showno(#n)
  100.  
  101. showyes(not #n)
  102.  
  103. endproc
  104.  
  105. ; ----------------------------------------------------------
  106. proc test_get_num()
  107.  
  108. .TESTDECL
  109. declare #my_num
  110.  
  111. #first_time = 1
  112.  
  113. loop
  114.     get_params(.NUMERIC,#first_time,"get_num")
  115.     #first_time = 0
  116.  
  117.     #my_num = *get_num($my_prompt,$my_def,"",#my_min,#my_max)
  118.     t:$skip   you entered <#my_num>
  119.  
  120. until (*no("repeat this test","",""))
  121.  
  122. endproc
  123.  
  124. ; ----------------------------------------------------------
  125.  
  126. proc get_params(#type,#first_time,$name)
  127.  
  128. if (not #first_time)
  129.     if (*no("Revise parameters","",""))
  130.         return
  131.     endif
  132. endif
  133.  
  134. signon($name)
  135. set_params(#type,#first_time)
  136.  
  137. endproc
  138.  
  139. ; ----------------------------------------------------------
  140.  
  141. proc set_params(#type,#first_time)
  142.  
  143. declare $min_prompt,$max_prompt,#min_lwr,#min_upr,#max_lwr,#max_upr, $is_oblig
  144.  
  145. $my_prompt=*get_str("   Enter a prompt string:",$my_prompt,"",0,40,0)
  146.  
  147. if (#type == .FILE)
  148.  
  149.     $my_path=*get_str("   Default path:",$my_path,"",0,40,0)
  150.     $my_file=*get_str("   Default file:",$my_file,"",0,8,0)
  151.     $my_ext=*get_str("   Default ext:",$my_ext,"",0,4,0)
  152.  
  153. else    ; string or numeric
  154.  
  155.     if (#type == .STRING)
  156.  
  157.         if ($my_def == "")
  158.             $my_def=*get_str("   Enter a default:",$my_def,"",0,40,0)
  159.         else if (*yes("   Default is <$my_def> - delete it","",""))
  160.             $my_def=
  161.         endif
  162.  
  163.         if (#first_time)
  164.             #my_max = 40
  165.         else
  166.             if (#my_oblig)
  167.                 $is_oblig=y
  168.             else
  169.                 $is_oblig=n
  170.             endif
  171.         endif
  172.  
  173.         if ($my_def == "")
  174.             #my_oblig = *yes("   Is the input obligatory",$is_oblig,"")
  175.         else
  176.             #my_oblig = 0
  177.         endif
  178.  
  179.         $min_prompt=Minimum length:
  180.         $max_prompt=Maximum length:
  181.  
  182.         if (#my_oblig)
  183.             #min_lwr = 1
  184.             #my_min = 1
  185.         else
  186.             #min_lwr = 0
  187.             #my_min = 0
  188.         endif
  189.         #min_upr = 39
  190.         #max_upr = 40
  191.  
  192.     else    ; it's numeric
  193.  
  194.         $min_prompt=Minimum value:
  195.         $max_prompt=Maximum value:
  196.         #min_lwr = .MININT
  197.         #min_upr = .MAXINT
  198.         #max_upr = .MAXINT
  199.  
  200.         if (#first_time)
  201.             #my_min = .MININT
  202.             #my_max = .MAXINT
  203.         endif
  204.  
  205.         loop
  206.             $my_def=*get_str("   Default:",$my_def,"",0,5,0)
  207.             exit if (($my_def == "") or (*isnumber($my_def)))
  208.             error("   The default must be a number","")
  209.         endloop
  210.     endif
  211.  
  212.     #my_min = *get_num("   $min_prompt","#my_min","",#min_lwr,#min_upr)
  213.  
  214.     if ((#type == .STRING) and (#my_min < 1))
  215.         #max_lwr = 1
  216.     else
  217.         #max_lwr = #my_min
  218.     endif
  219.  
  220.     #my_max = *between(#my_max,#max_lwr,#max_upr)
  221.  
  222.     #my_max = *get_num("   $max_prompt","#my_max","",#max_lwr,#max_upr)
  223.  
  224. endif
  225.  
  226. endproc
  227.  
  228. ; ----------------------------------------------------------
  229.  
  230. proc test_yes()
  231.  
  232. declare #my_yes
  233.  
  234. signon("yes")
  235.  
  236. loop
  237.     #my_yes = *yes("Answer yes or no (default not allowed)","","")
  238.     t:*showyes(#my_yes)#my_yes)
  239.     #my_yes = *yes("Answer yes or no","y","")
  240.     t:*showyes(#my_yes)#my_yes)
  241.     #my_yes = *yes("Answer yes or no","n","")
  242.     t:*showyes(#my_yes)#my_yes)
  243.     t:
  244. until (*no("Repeat this test","",""))
  245.  
  246. endproc
  247.  
  248. ; ----------------------------------------------------------
  249.  
  250. proc test_no()
  251.  
  252. declare #my_yes
  253.  
  254. signon("no")
  255.  
  256. loop
  257.     #my_yes = *no("Answer yes or no (default not allowed)","","")
  258.     t:*showno(#my_yes)#my_yes)
  259.     #my_yes = *no("Answer yes or no","y","")
  260.     t:*showno(#my_yes)#my_yes)
  261.     #my_yes = *no("Answer yes or no","n","")
  262.     t:*showno(#my_yes)#my_yes)
  263.     t:
  264. until (*no("Repeat this test","",""))
  265.  
  266. endproc
  267.  
  268. ; ----------------------------------------------------------
  269. proc signon($name)
  270.  
  271. kbflush()
  272. ch
  273. t:Test of \*$name()
  274. t:
  275.  
  276. endproc
  277.  
  278. ; ----------------------------------------------------------
  279.  
  280. numfunc between(#arg,#min,#max)  ; return copy of #arg forced between min & max
  281.  
  282. if (#arg < #min)
  283.     return (#min)
  284. else if (#arg > #max)
  285.     return (#max)
  286. else
  287.     return (#arg)
  288. endif
  289.  
  290. endfunc
  291.  
  292. ; ----------------------------------------------------------
  293.  
  294. proc test_get_filespec()
  295.  
  296. .TESTDECL
  297. declare $my_path,$my_file, $my_ext, $my_filespec
  298.  
  299. #first_time = 1
  300.  
  301. loop
  302.     get_params(.FILE,#first_time,"get_filespec")
  303.  
  304.     #first_time = 0
  305.  
  306.     $my_filespec=*get_filespec($my_prompt,$my_path,$my_file,$my_ext,"")
  307.     #sstep=0
  308.     t:$skip   You entered <$my_filespec>
  309. until (*no("Repeat this test","",""))
  310.  
  311. endproc
  312.  
  313.  
  314.